package org.example.thread;

import org.apache.tomcat.util.threads.ThreadPoolExecutor;

import java.util.concurrent.*;

public class CompleTableFutureDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService =
                new ThreadPoolExecutor(8,16,30000, TimeUnit.MILLISECONDS,
                        new LinkedBlockingQueue<>(100),new ThreadPoolExecutor.AbortPolicy());

        CompletableFuture<Integer> completableFuture01 =
                //提供一个线程的传值为100 ，并提供给线程池管理
                CompletableFuture.supplyAsync(()->100,
                executorService);
        //传入下一个线程操作
        CompletableFuture<Integer> completableFuture02 = completableFuture01.thenApplyAsync((a) -> {
            //在上个结果的拿到后进行处理操作，上一个结果是对象a,处理后的结果是b
            Integer b = a+10;
            return b;
        }, executorService).thenApplyAsync((a)->{
            Integer b = ++a;
           return b;
        },executorService);
        CompletableFuture completableFuture03 = completableFuture02.thenAcceptAsync((a)->{
            System.out.println("最终获得到的结果是:"+a);
        },executorService);
        System.out.println(completableFuture02.get());
        executorService.shutdown();

    }
}
